/*
 * Copyright (c) 2015, the Dart project authors.
 *
 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package vm.element

// This file is generated by the script: pkg/vm_service/tool/generate.dart in dart-lang/sdk.

import com.google.gson.JsonObject

/**
 * The {@link UnresolvedSourceLocation} class is used to refer to an unresolved breakpoint
 * location. As such, it is meant to approximate the final location of the breakpoint but it is not
 * exact.
 */
class UnresolvedSourceLocation(json: JsonObject) : Response(json) {

    /**
     * An approximate column number for the source location. This may change when the location is
     * resolved.
     *
     * Can return <code>null</code>.
     */
    fun getColumn(): Int {
        return getAsInt("column")
    }

    /**
     * An approximate line number for the source location. This may change when the location is
     * resolved.
     *
     * Can return <code>null</code>.
     */
    fun getLine(): Int {
        return getAsInt("line")
    }

    /**
     * The script containing the source location if the script has been loaded.
     *
     * Can return <code>null</code>.
     */
    fun getScript(): ScriptRef? {
        val obj = json.get("script")?.asJsonObject ?: return null
        val type = json.get("type")?.asString
        if ("Instance" == type || "@Instance" == type) {
            val kind = json.get("kind")?.asString
            if ("Null" == kind) return null
        }
        return ScriptRef(obj)
    }

    /**
     * The uri of the script containing the source location if the script has yet to be loaded.
     *
     * Can return <code>null</code>.
     */
    fun getScriptUri(): String? {
        return getAsString("scriptUri")
    }

    /**
     * An approximate token position for the source location. This may change when the location is
     * resolved.
     *
     * Can return <code>null</code>.
     */
    fun getTokenPos(): Int {
        return getAsInt("tokenPos")
    }
}
